﻿/// <reference path="jquery-1.4.2.js" />
/// <reference path="jsex.js" />


Site = {};


Site.ServerPath = '/';

Site.IsDebug = false;
Site.getJSON = function(url, data, callback) {
    if (url.indexOf('?') > 0)
        url += "&round=" + Math.random();
    else
        url += "?round=" + Math.random();
    $.ajax({
        type: "GET",
        cache: false,
        url: url,
        data: data,
        success: callback,
        dataType: 'json'
    });
};

$(document).ready(function () {
    $(".left_menu_sub").hide();
    $(".left_menu_bar").each(function () {
        var bar = $(this);
        var sub = bar.next();
        if (sub.find("table").length) {
            bar.css("cursor", "pointer");
            bar.click(function () {
                if (sub.is(":hidden")) {
                    $(".left_menu_sub").each(function () {
                        var self = $(this);
                        if (!self.is(":hidden"))
                            self.toggle(500);
                    });
                }
                sub.toggle(500);

            })
        } else {
            bar.css("cursor", "auto");
        }
    });
    var c1=$(".left_menu_sub:has(a.left_menu_sub_current)"); //.show()
    c1.prev().addClass("left_menu_sub_current"); //.css("color", "#80FFFF");
    //$("a.left_menu_sub_current").css("color", "#FDF786");
    $(".left_div_menu .left_menu_sub table").attr({ cellspacing: "5" }).find("tr:has(td[colspan!=2])").each(function () {
        var td = $(this).find("td:first");
        if (!td.is(".singleitem"))
            td.addClass("firsttd");
    });
    $(".left_div_menu .left_menu_sub table a[Authorize='False']").css({ color: "Black", cursor: "none" }).click(function () { return false; });

});

function _ParseInt(val) {
    var num, cleanInput, m, exp;
    exp = /^\s*[-\+]?\d+\s*$/;
    if (val.match(exp) == null)
        return null;
    num = parseInt(val, 10);
    return (isNaN(num) ? null : num);
}
function _ParseBool(val) {
    var expTRUE = new RegExp('^(\\s?)+TRUE(\\s?)+$');
    var expFALSE = new RegExp('^(\\s?)+FALSE(\\s?)+$');
    if (expTRUE.test(val.toString().toUpperCase())) {
        return true;
    } else if (expFALSE.test(val.toString().toUpperCase())) {
        return false;
    } else {
        throw Error('值'+val+'无法转换为bool类型');
    }
}
function _ParseDouble(val) {
    var num, cleanInput, m, exp;
    exp = new RegExp("^\\s*([-\\+])?(\\d*)\\.?(\\d*)\\s*$");
    m = val.match(exp);
    if (m == null)
        return null;
    if (m[2].length == 0 && m[3].length == 0)
        return null;
    cleanInput = (m[1] != null ? m[1] : "") + (m[2].length > 0 ? m[2] : "0") + (m[3].length > 0 ? "." + m[3] : "");
    num = parseFloat(cleanInput);
    return (isNaN(num) ? null : num);
}

function _ParseDate(val) {
    function GetFullYear(year) {
        var twoDigitCutoffYear = val.cutoffyear % 100;
        var cutoffYearCentury = val.cutoffyear - twoDigitCutoffYear;
        return ((year > twoDigitCutoffYear) ? (cutoffYearCentury - 100 + year) : (cutoffYearCentury + year));
    }
    var num, cleanInput, m, exp;
    var yearFirstExp = new RegExp("^\\s*((\\d{4})|(\\d{2}))([-/]|\\. ?)(\\d{1,2})\\4(\\d{1,2})\\.?\\s*$");
    m = val.match(yearFirstExp);
    var day, month, year;
    if (m != null && (((typeof (m[2]) != "undefined") && (m[2].length == 4)) || val.dateorder == "ymd")) {
        day = m[6];
        month = m[5];
        year = (m[2].length == 4) ? m[2] : GetFullYear(parseInt(m[3], 10));
    }
    else {
        if (val.dateorder == "ymd") {
            return null;
        }
        var yearLastExp = new RegExp("^\\s*(\\d{1,2})([-/]|\\. ?)(\\d{1,2})(?:\\s|\\2)((\\d{4})|(\\d{2}))(?:\\s\u0433\\.|\\.)?\\s*$");
        m = val.match(yearLastExp);
        if (m == null) {
            return null;
        }
        if (val.dateorder == "mdy") {
            day = m[3];
            month = m[1];
        }
        else {
            day = m[1];
            month = m[3];
        }
        year = ((typeof (m[5]) != "undefined") && (m[5].length == 4)) ? m[5] : GetFullYear(parseInt(m[6], 10));
    }
    month -= 1;
    var date = new Date(year, month, day);
    if (year < 100) {
        date.setFullYear(year);
    }
    return (typeof (date) == "object" && year == date.getFullYear() && month == date.getMonth() && day == date.getDate()) ? date.valueOf() : null;

}


function getJSON(url, data, callback) {
    if (url.indexOf('?') > 0)
        url += "&round=" + Math.random();
    else
        url += "?round=" + Math.random() ;
    $.ajax({
        type: "GET",
        cache: false,
        url: url,
        data: data,
        success: callback,
        dataType: 'json'
    });
}
function CreateWiteDiv(left, top, width, height, imgUrl, msg) {
    var div_card = document.createElement("div");
    with (div_card.style) {
        background ="White";
        borderStyle = "none";
        borderWidth = "0";
        position = "absolute";
        textAlign = "center";
        fontFamily = "Verdana,Arial,Helvetica,sans-serif";
    }
    div_card.style.width = width;
    div_card.style.height = height;
    if (top > 0)
        div_card.style.top = top;
    else
        div_card.style.top = window.screen.height / 2;
    if(left>0)
        div_card.style.left = left;
    else
        div_card.style.left=window.screen.width/2

    div_card.cellSpacing = "0";
    div_card.cellPadding = "0";
    div_card.className = 'WiteDiv';
    var table = document.createElement('table');
    with (table.style) {
        borderStyle = "none";
        borderWidth = "0";
    }
    table.cellSpacing = "0";
    table.cellPadding = "0";

    var tr = table.insertRow(-1);
    var td_left = tr.insertCell(-1);
    img = document.createElement("img");
    img.src = imgUrl;
    td_left.appendChild(img);

    var td_right = tr.insertCell(-1);
    td_right.align = "center";
    var span = document.createElement("span");
    span.innerHTML = msg;
    td_right.appendChild(span);

    div_card.appendChild(table);
    document.body.appendChild(div_card);
    HideDiv();
}
var IsHideDiv = false;
function HideDiv() {
    if (IsHideDiv) {
        $('.WiteDiv').hide();
    } else {
        window.setTimeout('HideDiv()', 1000);
    }
}
